package config_order.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;

import java.beans.PropertyDescriptor;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2022-08-16 17:14
 */
//@Component
public class MyInstantiationAwareBeanPostProcessor implements InstantiationAwareBeanPostProcessor {

	@Override
	public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
		if(beanName.contains("classA")){
			System.out.println("实例化前:"+System.currentTimeMillis());
		}
		return null;
	}

	@Override
	public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
		if(beanName.contains("classA")){
			System.out.println("实例化后:"+System.currentTimeMillis());
		}
		return true;
	}

	@Override
	public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException {
		if(beanName.contains("classA")){
			System.out.println("属性增强:"+System.currentTimeMillis());
		}
		return null;
	}

	@Override
	public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {
		return null;
	}

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		if(beanName.contains("classA")){
			System.out.println("初始化前:"+System.currentTimeMillis());
		}
		return bean;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		if(beanName.contains("classA")){
			System.out.println("初始化后:"+System.currentTimeMillis());
		}
		return bean;
	}
}
